<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{css/succ.css}">
    <link rel="stylesheet" th:href="@{webjars/bootstrap/4.5.2/css/bootstrap.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.js}"></script>
</head>
<body>

<!--<div th:insert="~{success::#left}"></div>-->


<!--<div th:insert="~{success::#top}"></div>-->

<h2><a class="btn btn-sm btn-success" th:href="@{/emp}">员工添加</a></h2>
<table class="table table-striped">
    <thead>
        <tr>
            <th>#</th>
            <th>Name</th>
            <th>email</th>
            <th>gender</th>
            <th>department</th>
            <th>birth</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        <tr th:each="emp:${emps}">
            <td>[[${emp.id}]]</td>
            <td>[[${emp.lastName}]]</td>
            <td>[[${emp.email}]]</td>
            <td>[[${emp.gender}==0 ? '男':'女' ]]</td>
            <td>[[${emp.department.departmentName}]]</td>
            <td>[[${#dates.format(emp.birth, 'yyyy-MM-dd HH:mm:ss')}]]</td>
            <td>
                <a class="btn btn-sm btn-success" th:href="@{/emp/}+${emp.id}">编辑</a>
                <button th:attr="del_uri = @{/emp/}+${emp.id}" class="btn btn-sm btn-danger deleteBtn">删除</button>
            </td>
        </tr>
    </tbody>

</table>

<form id="deleteEmpForm" method="post">
    <input type="hidden" name="_method" value="delete">
</form>


<script>
    $(".deleteBtn").click(function () {
        //获取del_uri
        let del_uri = $(this).attr("del_uri");
        //设置action并提交
        $("#deleteEmpForm").attr("action",del_uri).submit();
        return false;
    })
</script>

</body>
</html>